<template>
	<view class="container">
		<view class="add-shop" @click="openPupop">
			添加普通代理商
		</view>
		<block v-for="item in dailiList" :key="item.id">
			<view class="shop">
				<view class="item">
					<text class="label">名称：</text>
					<text class="value">{{item.shopName}}</text>
				</view>
				<view class="item">
					<text class="label">手机号：</text>
					<text class="value">{{item.phone}}</text>
				</view>
				<view class="footer" style="border-bottom: none;">
					<!-- 	<view class="left">
						<text style="font-size: 30rpx;color: #666;">积分：</text>
						<text style="font-size: 32rpx;font-weight: bold;color: #ff0000;">2000</text>
					</view> -->
					<view class="right" style="width: 260rpx;background: #00008B;" @click="openZizhanghaoDailog(item)">
						子账号设置({{item.authorizationNum}}个)
					</view>
					<view class="right" @click="openChongzhi(item.id)">
						充值
					</view>

				</view>
			</view>
		</block>

		<view class="pupop" v-if="showChongzhiPupop">
			<view class="content" style="height: 500rpx;">
				<view class="pupop-header">
					<view>积分充值</view>
					<image src="../../static/close.png" style="height:50rpx;width: 50rpx;" @click="closeChongzhiPupop">
					</image>
				</view>

				<view class="pupop-body">
					<view style="font-size: 32rpx;display: flex;align-items: center;">
						<text>积分：</text>
						<input style="height: 70rpx;flex:1;border: 1rpx solid #eee;padding-left: 10rpx;"
							v-model="chongzhiForm.integral" placeholder="请输入积分" />
					</view>
				</view>

				<view class="code-btn" @click="sureChongzhi">
					确定充值
				</view>
			</view>
		</view>
		<view class="pupop" v-if="showZizhanghaoDialog">
			<view class="content" style="height: 500rpx;">
				<view class="pupop-header">
					<view>子账号设置</view>
					<image src="../../static/close.png" style="height:50rpx;width: 50rpx;"
						@click="cancelZizhanghaoDialog">
					</image>
				</view>

				<view class="pupop-body">
					<view style="font-size: 32rpx;display: flex;align-items: center;">
						<text>子账号个数：</text>
						<input style="height: 70rpx;flex:1;border: 1rpx solid #eee;padding-left: 10rpx;"
							v-model="zizhanghaoForm.authorizationNum" placeholder="请输入子账号个数" />
					</view>
				</view>

				<view class="code-btn" @click="submitZizhanghao">
					确定
				</view>
			</view>
		</view>
		<!-- 字体颜色模态框 start -->
		<view class="pupop" v-if="showPupop">
			<view class="content">
				<view class="pupop-header">
					<view>添加普通代理</view>
					<image src="../../static/close.png" style="height:50rpx;width: 50rpx;" @click="closePupop"></image>
				</view>

				<view class="pupop-body">
					<view class="item">
						<view class="left">代理名称</view>
						<input class="right" v-model="form.shopName" placeholder="请输入普通代理商名称" />
					</view>
					<view class="item">
						<view class="left">积分</view>
						<input class="right" v-model="form.integral" type="number" placeholder="请输入积分" />
					</view>
					<view class="item">
						<view class="left">手机号</view>
						<input class="right" v-model="form.phone" placeholder="请输入手机号" />
					</view>
					<view class="item">
						<view class="left">密码</view>
						<input class="right" disabled style="background: rgb(245, 247, 250);color: #666;"
							placeholder="默认登录密码为123456" />
					</view>
				</view>

				<view class="code-btn" @click="submitForm">
					确定添加
				</view>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	import Http from '../../utils/http';
	const http = new Http()
	export default {
		data() {
			return {
				showPupop: false,
				form: {
					shopName: "",
					phone: "",
					integral: 0,
					type: 2
				},
				dailiList: [],
				showChongzhiPupop: false,
				chongzhiForm: {
					integral: 0,
					id: null
				},
				showZizhanghaoDialog: false,
				zizhanghaoForm: {
					id: null,
					authorizationNum: 10
				},
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			getList(){
				http.get(`admin/agentShop/getDailiList`).then(res => {
					console.log("****", res);
					this.dailiList = res.data.data
				})
			},
			//打开子账号
			openZizhanghaoDailog(item) {
				this.zizhanghaoForm.id = item.id
				this.zizhanghaoForm.authorizationNum = item.authorizationNum
				this.showZizhanghaoDialog = true
			},
			cancelZizhanghaoDialog() {
				this.showZizhanghaoDialog = false
				this.zizhanghaoForm.id = null
				this.zizhanghaoForm.authorizationNum = 0
				this.getList()
			},
			//提交子账号
			submitZizhanghao() {
				console.log("====", this.zizhanghaoForm);
				
				http.post(`admin/agentShop/updateAgentShopAuthNum`,this.zizhanghaoForm).then(res => {
					this.showZizhanghaoDialog = false
					this.zizhanghaoForm.id = null
					this.zizhanghaoForm.authorizationNum = 0
					uni.showToast({
						title:"设置成功"
					})
					this.getList()
				})
				

			},
			submitForm() {
				console.log("===", this.form);
				http.post(`admin/agentShop/addAgentShop`, this.form).then(res => {
					console.log("====》", res);
					if (res.data.code != 200) {
						return uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
					}
					this.showPupop = false;
					this.resetForm()
					this.getList()
					return uni.showToast({
						title: "添加成功"
					})
				})
			},
			openPupop() {
				this.showPupop = true;
			},
			closePupop() {
				this.showPupop = false;
				this.resetForm()
			},
			closeChongzhiPupop() {
				this.showChongzhiPupop = false
			},
			//打开充值
			openChongzhi(id) {
				console.log(id);
				this.chongzhiForm.id = id
				this.showChongzhiPupop = true
			},
			//确定充值
			sureChongzhi() {
				console.log("确定", this.chongzhiForm);
				http.post(`admin/agentShop/dailiChongzhi`, this.chongzhiForm).then(res => {
					console.log("====》", res);
					if (res.data.code != 200) {
						return uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
					}
					this.showChongzhiPupop = false;
					this.resetChongzhiForm()
					return uni.showToast({
						title: "充值成功"
					})
				})
				// this.showChongzhiPupop = false
			},
			resetForm() {

				this.form.shopName = ''
				this.form.phone = ''
				this.form.integral = 0
				this.form.type = 2
			},
			resetChongzhiForm() {

				this.chongzhiForm.integral = 0
				this.chongzhiForm.id = null
			}

		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #f1f1f1;
	}

	.container {}

	.add-shop {
		margin: 30rpx;
		width: 260rpx;
		height: 60rpx;
		background: #ff0000;
		color: #fff;
		font-size: 30rpx;
		line-height: 60rpx;
		border-radius: 10rpx;
		text-align: center;
	}

	.pupop {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 9;

		.content {
			background: #fff;
			border-top-left-radius: 30rpx;
			border-top-right-radius: 30rpx;

			position: fixed;
			z-index: 19;
			height: 780rpx;
			bottom: 0;
			left: 0;
			right: 0;

			.pupop-header {
				display: flex;
				height: 100rpx;
				justify-content: space-between;
				align-items: center;
				font-size: 36rpx;
				font-weight: bold;
				border-bottom: 1rpx solid #f1f1f1;
				padding: 0 30rpx;

			}

			.pupop-body {
				margin: 20rpx 30rpx;

				.item {
					display: flex;
					align-items: center;
					margin-bottom: 30rpx;

					.left {
						width: 130rpx;
						font-size: 30rpx;
					}

					.right {
						flex: 1;
						border: 1rpx solid #f1f1f1;
						font-size: 30rpx;
						color: #666;
						height: 70rpx;
						border-radius: 12rpx;
						padding-left: 10rpx;
					}
				}

			}

			.code-btn {
				height: 80rpx;
				line-height: 80rpx;
				margin: 30rpx;
				background: #ff0000;
				margin-top: 50rpx;
				border-radius: 50rpx;
				text-align: center;
				color: #fff;
			}
		}
	}

	.shop {
		margin: 0 20rpx;
		margin-bottom: 20rpx;
		padding: 0 20rpx;
		border-radius: 20rpx;
		background: #fff;

		.item {
			display: flex;
			height: 70rpx;
			line-height: 70rpx;
			border-bottom: 1rpx solid #f1f1f1;

			.label {
				font-size: 30rpx;
				color: #666;
			}

			.value {
				font-size: 32rpx;
				color: #333;
			}
		}

		.footer {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 70rpx;
			line-height: 70rpx;
			border-bottom: 1rpx solid #f1f1f1;

			.right {
				width: 90rpx;
				height: 50rpx;
				background: #ff0000;
				color: #fff;
				font-size: 28rpx;
				line-height: 50rpx;
				border-radius: 10rpx;
				text-align: center;
			}
		}
	}
</style>